﻿<UserControl x:Class="Samba.Modules.TableModule.TableSelectorView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:Common="clr-namespace:Samba.Presentation.Common;assembly=Samba.Presentation.Common"
     xmlns:FxButton="clr-namespace:FlexButton;assembly=FlexButton" mc:Ignorable="d" d:DesignHeight="300"
     d:DesignWidth="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="9*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid Grid.Column="1" Grid.Row="1" Background="Silver" Grid.RowSpan="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <FxButton:FlexButton Margin="2" Height="60" Grid.Row="0" Content="{LocText Close}"
                 ButtonColor="Red" Command="{Binding CloseScreenCommand}" />
            <ItemsControl Grid.Row="1" ItemsSource="{Binding TableScreens}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <FxButton:FlexButton Margin="2" Height="60" Content="{Binding Name}" Command="{Binding DataContext.SelectTableCategoryCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}}"
                             CommandParameter="{Binding}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
        <TextBlock TextAlignment="Center" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
             Padding="5" Text="{Binding Feedback}" FontSize="18" FontWeight="Bold" Visibility="{Binding IsFeedbackVisible,Converter={StaticResource VisibilityConverter}}"
             Background="{Binding FeedbackColor}" Foreground="{Binding FeedbackForeground}" />
        <TabControl Grid.Column="0" Grid.Row="1" SelectedIndex="{Binding SelectedDisplayMode}"
             BorderThickness="0" Padding="0">
            <TabControl.Background>
                <SolidColorBrush />
            </TabControl.Background>
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Setter Property="Margin" Value="0" />
                </Style>
            </TabControl.ItemContainerStyle>
            <ItemsControl ItemsSource="{Binding Tables}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid Columns="{Binding SelectedTableScreen.ColumnCount}" VerticalAlignment="{Binding TablesVerticalAlignment}" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <FxButton:FlexButton Content="{Binding Name}" Height="{Binding ButtonHeight}" Margin="0,0,4,4"
                             ButtonColor="{Binding ButtonColor}" IsEnabled="{Binding IsEnabled}" Command="{Binding DataContext.TableSelectionCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ItemsControl}}}"
                             CommandParameter="{Binding}" />
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
            <Border Name="brd" BorderThickness="1" BorderBrush="Silver" Background="{Binding SelectedTableScreen.BackgroundColor}">
                <Viewbox Stretch="Uniform">
                    <Grid>
                        <Image Source="{Binding SelectedTableScreen.BackgroundImage}" HorizontalAlignment="Left"
                             VerticalAlignment="Top" Stretch="None">
                        </Image>
                        <Common:DiagramCanvas SnapsToDevicePixels="True" MinWidth="640" MinHeight="480" EditingMode="None"
                             Source="{Binding Tables}" Name="DiagramCanvas" Background="Transparent">
                            <Common:DiagramCanvas.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Name="miDesignMode" Header="{LocText EditMode}"
                                         Click="MenuItem_Click" IsEnabled="{Binding CanDesignTables}" />
                                </ContextMenu>
                            </Common:DiagramCanvas.ContextMenu>
                        </Common:DiagramCanvas>
                    </Grid>
                </Viewbox>
            </Border>
        </TabControl>
        <UniformGrid Grid.Row="2" Grid.Column="0" Columns="2" Rows="1" MaxHeight="60" Visibility="{Binding IsPageNavigatorVisible,Converter={StaticResource VisibilityConverter}}">
            <FxButton:FlexButton Command="{Binding DecPageNumberCommand}" Content="{Binding DecPageNumberCommand.Caption}" />
            <FxButton:FlexButton Margin="3,0" Command="{Binding IncPageNumberCommand}" Content="{Binding IncPageNumberCommand.Caption}" />
        </UniformGrid>
    </Grid>
</UserControl>